// 方法能给用户定义的类型添加新的行为
package main

import "fmt"

type user struct {
    name string
    email string
}

func (u user) notify() {
    fmt.Printf("Sending User Email to %s<%s>\n", u.name, u.email)
}

func (u *user) changeEmail(email string) {
    u.email = email
}

func main() {
    bill := user {"Bill", "bill@email.com"}
    bill.notify()

    lisa := &user {"Lisa", "lisa@email.com"}
    lisa.notify()

    bill.changeEmail("bill@newdomain.com")
    bill.notify()

    lisa.changeEmail("lisa@newdomain.com")
    lisa.notify()

    fmt.Println("convert to use value")
    (*lisa).notify()

    fmt.Println("convert to use pointer")
    (&bill).changeEmail("bill@newdomain2.com")
    bill.notify()
}
